package com.ruoyi.job.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.job.domain.BzFlowDay;
import com.ruoyi.job.mapper.IBzFlowDayMapper;
import com.ruoyi.job.service.IBzFlowDayService;
import org.springframework.stereotype.Service;

@Service
public class BzFlowDayServiceImpl extends ServiceImpl<IBzFlowDayMapper, BzFlowDay> implements IBzFlowDayService {
    @Override
    public long countByIpAndDayStr(String ip, String dateStr) {
        LambdaQueryWrapper<BzFlowDay> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BzFlowDay::getIp, ip)
                .eq(BzFlowDay::getDayStr, dateStr);
        return count(queryWrapper);
    }

    @Override
    public void updateByIpAndDayStr(BzFlowDay bzFlowDay, String ip, String format) {
        LambdaUpdateWrapper<BzFlowDay> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(BzFlowDay::getIp, ip)
                .eq(BzFlowDay::getDayStr, format)
                .set(BzFlowDay::getTotalFlow, bzFlowDay.getTotalFlow())
                .set(BzFlowDay::getDayFinalFlow, bzFlowDay.getDayFinalFlow())
                .set(BzFlowDay::getCreateTime, bzFlowDay.getCreateTime());
        this.update(updateWrapper);
    }
}
